package com.zj.project.common.expand

import android.app.Application
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build

/**
 * createTime:2021/8/3 11:19
 * auth:张继
 * des:
 */

fun Application.connectivityManage(): ConnectivityManager {
    return this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
}


fun Application.isConnected(): Boolean {
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        val capabilities: NetworkCapabilities = this.connectivityManage()
            .getNetworkCapabilities(this.connectivityManage().activeNetwork)!!
        capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
    } else {
        this.connectivityManage().activeNetworkInfo!!.isConnected
    }
    return false
}
